package com.example.demo2.test.pong;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import okhttp3.WebSocket;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class BinancePong implements Runnable {

	private static WebSocket webSocket;
	@Override
	public  void run(){
		while(true) {
			try {
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("method","SUBSCRIBE");
			List<String> list = new ArrayList<>();
			list.add("pong");
			jsonObject.put("params",list);
			jsonObject.put("id",System.currentTimeMillis());
			webSocket.send(jsonObject.toJSONString());
		}
	}
	public BinancePong(WebSocket webSocket){
		this.webSocket = webSocket;
	}
}